// Package adminin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2023 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
package adminin

import (
	"context"
	"github.com/go-pay/gopay/wechat/v3"
	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/errors/gerror"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
)

// CashViewInp 获取信息
type CashViewInp struct {
	Id int64 `json:"id" v:"required#提现ID不能为空" dc:"提现ID"`
}

type CashViewModel struct {
	entity.AdminCash
	MemberCash
}

// CashListInp 获取列表
type CashListInp struct {
	form.PageReq
	form.StatusReq
	MemberId   int64   `json:"memberId"`
	MemberName string  `json:"memberName"`
	CreatedAt  []int64 `json:"created_at"`
	StoreName  string  `json:"storeName"`
}

type CashListModel struct {
	AdminMemberRealName string `json:"adminMemberRealName" dc:"真实姓名"`
	AdminMemberNickname string `json:"adminMemberNickname" dc:"微信昵称"`
	AdminMemberRoleId   int64  `json:"adminMemberRoleId" dc:"角色ID"`
	StoreName           string `json:"storeName" dc:"门店名称"`
	entity.AdminCash
}

// CashApplyInp 申请提现
type CashApplyInp struct {
	Money    float64 `json:"money"     description:"提现金额"`
	MemberId int64
}

// CashPaymentInp 提现打款处理
type CashPaymentInp struct {
	Id     int64  `json:"id"        description:"ID"`
	Status int64  `json:"status"    description:"状态码"`
	Msg    string `json:"msg"       description:"处理结果"`
}

type CashPaymentNotifyInp struct {
	Status               int     `json:"status"`
	ErrorCode            string  `json:"errorCode"`
	ErrorCodeDesc        string  `json:"errorCodeDesc"`
	UserNo               string  `json:"userNo"`
	TradeMerchantNo      string  `json:"tradeMerchantNo"`
	MerchantOrderNo      string  `json:"merchantOrderNo"`
	PlatformSerialNo     string  `json:"platformSerialNo"`
	ReceiverAccountNoEnc string  `json:"receiverAccountNoEnc"`
	ReceiverNameEnc      string  `json:"receiverNameEnc"`
	PaidAmount           float64 `json:"paidAmount"`
	Fee                  float64 `json:"fee"`
	Hmac                 string  `json:"hmac"`
}

type WalletCreditsLogInp struct {
	form.PageReq
	StoreID        int64  `json:"storeId" description:"商户ID"`
	Type           int    `json:"type" description:"类型：1、收入，2、支出"`
	CreditType     string `json:"creditType" description:"变动类型：积分-integral，余额-balance"`
	BizType        int    `json:"bizType" description:"业务类型：1、钱包（默认），2、佣金"`
	CommissionType int    `json:"commissionType" description:"佣金类型：0-所有（默认），1-售卡，2-礼包，3-团购"`
}

func (in *WalletCreditsLogInp) Filter(ctx context.Context) (err error) {
	if in.CreditType != "" && in.CreditType != consts.CreditTypeIntegral && in.CreditType != consts.CreditTypeBalance {
		err = gerror.New("变动类型设置错误")
		return
	}
	if in.Type != 0 && in.Type != 1 && in.Type != 2 {
		err = gerror.New("查询类型设置错误")
		return
	}
	if in.BizType != 0 && in.BizType != 1 && in.BizType != 2 {
		err = gerror.New("业务类型设置错误")
		return
	} else if in.BizType == 0 {
		in.BizType = 1
	}
	return
}

type WalletCreditsLogModel struct {
	entity.AdminCreditsLog
	StatusName     string  `json:"statusName" description:"状态名称（处理中、打款中、审核中、审核通过、提现异常、提现成功）"`
	OrderUseAmount float64 `json:"orderUseAmount" description:"订单金额"`
	//OrderMemberCardId   int64       `json:"orderMemberCardId" description:"会员卡ID"`
	//OrderOrderType      string      `json:"orderOrderType" description:"订单类型"`
	AdminMemberNickname string      `json:"adminMemberNickname" dc:"昵称"`
	ProductName         string      `json:"productName" dc:"商品名称"`
	ProductMainImage    *gjson.Json `json:"productMainImage" dc:"商品主图"`
	MemberCardName      string      `json:"memberCardName" dc:"会员卡名称"`
	MemberCardImgUrl    string      `json:"memberCardImgUrl" dc:"会员卡图片"`
	CommissionType      int         `json:"commissionType" description:"佣金类型：1-售卡，2-礼包，3-团购"`
}

type WalletWithdrawToWechatInp struct {
	WalletCreditsLogID int64 `json:"walletCreditsLogId" v:"required#钱包变动ID不能为空" dc:"钱包变动ID"`
}

type WalletWithdrawToWechatModel struct {
	wechat.TransferBills
	//payLog.MchId
	MchId string `json:"mch_id" description:"商户号"`
}

type WalletCommissionStatModel struct {
	TotalCommission          float64 `json:"totalCommission" description:"总佣金"`
	TotalGiftCommission      float64 `json:"totalGiftCommission" description:"礼包总收益"`
	TotalSaleCommission      float64 `json:"totalSaleCommission" description:"售卡总收益"`
	TotalGroupCommission     float64 `json:"totalGroupCommission" description:"团购总收益"`
	TotalEcommerceCommission float64 `json:"totalEcommerceCommission" description:"电商总收益"`
	TodayCommission          float64 `json:"todayCommission" description:"今日收益"`
	TodayGiftCommission      float64 `json:"todayGiftCommission" description:"礼包今日收益"`
	TodaySaleCommission      float64 `json:"todaySaleCommission" description:"售卡今日收益"`
	TodayGroupCommission     float64 `json:"todayGroupCommission" description:"团购今日收益"`
	TodayEcommerceCommission float64 `json:"todayEcommerceCommission" description:"电商今日收益"`
}
